/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.tothgya.timetable;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;

/**
 *
 * @author tothgya
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            org.apache.commons.cli.CommandLineParser parser = new PosixParser();
            Options o = new Options();
            o.addOption("f", "from", true, "The starting point of your journey");
            o.addOption("t", "to", true, "The destination of your journey");
            o.addOption("d", "date", true, "The time of the journey");
            CommandLine cl = parser.parse(o, args);

            String fromString = cl.getOptionValue("f", "Debrecen");
            String toString = cl.getOptionValue("t", "Nyíregyháza");
            Calendar date = Calendar.getInstance();
            try {
                date.setTime(new SimpleDateFormat("y-MM-dd").parse(cl.getOptionValue("date")));
            } catch (java.text.ParseException pe) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, pe);
            } catch (NullPointerException npe) {
                Logger.getLogger(Main.class.getName()).log(Level.WARNING, null, npe);
            }
            
            TimetableFactory tf = new hu.tothgya.timetable.volan.TimetableFactory(
                    fromString,
                    toString,
                    Calendar.getInstance());
/*
            DateFormat df = new SimpleDateFormat("kk:mm");

            // Print possible journeys
            int maxLength = 0;
            Timetable table = tf.getJourneyTimetable();

            for (String stop : table.rows.keySet()) {
                maxLength = Math.max(maxLength, stop.length());
            }

            for (String stop : table.rows.keySet()) {
                StringBuilder buffer = new StringBuilder(String.format("%-" + maxLength + "s ", stop));
                for (Calendar c : table.rows.get(stop)) {
                    if (c != null) {
                        buffer.append(df.format(c.getTime())).append(' ');
                    } else {
                        buffer.append(" . .  ");
                    }
                }
                System.out.println(buffer.toString());
            }
            
            maxLength = 0;
            table = tf.getConnectionTimeTable();

            for (String stop : table.rows.keySet()) {
                maxLength = Math.max(maxLength, stop.length());
            }

            for (String stop : table.rows.keySet()) {
                StringBuilder buffer = new StringBuilder(String.format("%-" + maxLength + "s ", stop));
                for (Calendar c : table.rows.get(stop)) {
                    if (c != null) {
                        buffer.append(df.format(c.getTime())).append(' ');
                    } else {
                        buffer.append(" . .  ");
                    }
                }
                System.out.println(buffer.toString());
            }


*/
        } catch (ParseException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
